package com.itheima.health.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.service.OrderService;
import com.itheima.health.utils.redis.RedisUtil;
import com.itheima.health.utils.resources.RedisMessageConstant;
import com.itheima.health.utils.sms.ValidateCodeUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/order")
@Api(tags = "传智健康预约模块之套餐管理")
public class OrderController {

    @Reference
    private OrderService orderService;

    @GetMapping("sendCodeToYourTelephone/{telephone}")
    @ApiOperation(value = "查询功能",notes = "检查项查询列表信息")
    public Result   sendCodeToYourTelephone(@PathVariable("telephone")String telephone){
//        生成随机验证码 发给手机
        String code = ValidateCodeUtils.generateValidateCode(4);
//        aliyun工具类 测试开发  上线时打开
//        SmsUtils.validUserTelephone(telephone,code);//真实发短信
//        90s验证码存放redis
        RedisUtil.set(RedisMessageConstant.SENDTYPE_ORDER+telephone,code,90, TimeUnit.SECONDS);
        return  new Result(code);
    }

    @PostMapping("add")
    @ApiOperation(value = "查询功能",notes = "检查项查询列表信息")
    public Result  add(@RequestBody Map map){
//       下单操作
        return  new Result(orderService.add(map));
    }
    @GetMapping("findOrderInfoByOrderId/{oid}")
    @ApiOperation(value = "查询功能",notes = "检查项查询列表信息")
    public Result findOrderInfoByOrderId(@PathVariable("oid")int oid){
//       下单操作
        return  new Result(orderService.findOrderInfoByOrderId(oid));
    }


}
